package rootpackege.spring.websocket.basicwebsocket;

import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import rootpackege.spring.controller.websocket.Basicwebsocket;
/**
 * 启用比较底层的websocket，即原生的websocket  原生格式浏览器支持行比较差
 * @author BriansPC
 */
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer{

	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry register) {
		/**
		 * 当不添加.withSockJS()时，使用的是原生的websocket，
		 * SockJS是模拟了websocket,当浏览器不支持websocket通讯时，会自动通过其他方式实现
		 */
		register.addHandler(basicwebsocket(), "/basic").withSockJS();
		
	}
	@Bean
	public Basicwebsocket basicwebsocket(){
		return new Basicwebsocket();
	}
}
